home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d22 / fixfat.arc / FAT.FIX next >
Text File  |  1988-03-24  |  17KB  |  356 lines

  1. October 20, 1987
  2.  
  3. It doesn't take a trojan to wipe out your hard disk!  My FATs 
  4. (File Allocation Table) were wiped out when I had several TSRs
  5. loaded, a DOS shell on top of those and I loaded another
  6. COMMAND.COM on top of that.  When my word processor ran out of
  7. memory the whole stack of programs crashed and wrote garbage
  8. over my FAT.  When I rebooted the computer it wouldn't boot
  9. off the hard disk.  I hadn't backed up my drives for four months
  10. and I was facing the loss of close to 40MB of memory off two 20MB
  11. drives.
  12.  
  13. When I ran CHKDSK it came up with the cyptic message "Probable 
  14. non-DOS disk.  Continue (Y/N)?"  Of course it was a DOS disk.  
  15. What was going on?  
  16.  
  17. Well I finally figured out I had access to a couple of 
  18. subdirectories but my disk was obviously wasted.  I was 
  19. desperate.  What do I do now?  Norton Utilities wouldn't read the 
  20. disk saying I was running out of memory.  I didn't have MACE so I 
  21. don't know how that program would have worked.  
  22.  
  23. Then I remembered -- there are two copies of the FAT on a disk.  
  24. It seems DOS writes two copies of the FAT every time a change is 
  25. made but it only reads the first when reading the disk.  The 
  26. second FAT isn't even used for CHKDSK.  Was that FAT still in one 
  27. piece?  Fortunately it was.  Now all I had to do was get the 
  28. second copy of the FAT copied over to where the first one was.  
  29. How do you do this?  If you're like me you take a stab at it 
  30. using DEBUG.  It actually took me three days to figure out how 
  31. the process worked but once I knew all the steps it only took 
  32. about 15 minutes for the entire operation.  
  33.  
  34. I'm writing this file in the hope that I can help someone else in 
  35. similar circumstances to bypass the three day portion.  I have 
  36. two Seagate ST-225's formatted under 3.10 and I'm not sure that 
  37. everything will work the same for other versions of DOS or if you 
  38. have a RLL controller.  But what are your alternatives?
  39.  
  40. First let me explain how a hard drive is set up at the byte 
  41. level.  Your disk is set up with sectors labeled in ascending 
  42. sequence starting at zero.  Depending under what DOS you are 
  43. formatted with, the Boot sector occupies the first sector, the FAT 
  44. is in sectors 1-82, the root directory is sector 83 and all the 
  45. rest of your subdirectories and files occupy the remainder of the 
  46. disk.  So right now we have:
  47.             Sector 0  Boot record
  48.             Sector 1-82 FATs
  49.             Sector 83 Root directory
  50.             Sector 84-? Subdirectories and files
  51.             
  52. Using DEBUG the BOOT sector should look like this under 3.10 
  53. (similar under other versions).  Notice the identifying IBM 3.1 
  54. on the first line.  This is the version the disk was formatted 
  55. under.
  56.  
  57. xxxx:0100  EB 29 90 49 42 4D 20 20-33 2E 31 00 02 04 01 00   .).IBM  3.1.....   
  58. xxxx:0110  02 00 02 3B A2 F8 29 00-11 00 04 00 11 00 80 00   ...;..).........   
  59. xxxx:0120  00 00 00 00 0F 00 00 00-00 01 00 FA 33 C0 8E D0   ............3...   
  60. xxxx:0130  BC 00 7C 16 07 BB 78 00-36 C5 37 1E 56 16 53 BF   ..|...x.6.7.V.S.   
  61. xxxx:0140  20 7C B9 0B 00 FC AC 26-80 3D 00 74 03 26 8A 05    |.....&.=.t.&..   
  62. xxxx:0150  AA 8A C4 E2 F1 06 1F 89-47 02 C7 07 20 7C FB CD   ........G... |..   
  63. xxxx:0160  13 72 67 A0 10 7C 98 F7-26 16 7C 03 06 1C 7C 03   .rg..|..&.|...|.   
  64. xxxx:0170  06 0E 7C A3 34 7C A3 2C-7C B8 20 00 F7 26 11 7C   ..|.4|.,|. ..&.|   
  65. xxxx:0180  8B 1E 0B 7C 03 C3 48 F7-F3 01 06 2C 7C BB 00 05   ...|..H....,|...   
  66. xxxx:0190  A1 34 7C E8 96 00 B8 01-02 E8 AA 00 72 19 8B FB   .4|.........r...   
  67. xxxx:01A0  B9 0B 00 BE BE 7D F3 A6-75 0D 8D 7F 20 BE C9 7D   .....}..u... ..}   
  68. xxxx:01B0  B9 0B 00 F3 A6 74 18 BE-5F 7D E8 61 00 32 E4 CD   .....t.._}.a.2..   
  69. xxxx:01C0  16 5E 1F 8F 04 8F 44 02-CD 19 BE A8 7D EB EB A1   .^....D.....}...   
  70. xxxx:01D0  1C 05 33 D2 F7 36 0B 7C-FE C0 A2 31 7C A1 2C 7C   ..3..6.|...1|.,|   
  71. xxxx:01E0  A3 32 7C BB 00 07 A1 2C-7C E8 40 00 A1 18 7C 2A   .2|....,|.@...|*   
  72. xxxx:01F0  06 30 7C 40 50 E8 4E 00-58 72 CF 28 06 31 7C 76   .0|@P.N.Xr.(.1|v   
  73. xxxx:0200  0C 01 06 2C 7C F7 26 0B-7C 03 D8 EB D9 8A 2E 15   ...,|.&.|.......   
  74. xxxx:0210  7C 8A 16 1E 7C 8B 1E 32-7C EA 00 00 70 00 AC 0A   |...|..2|...p...   
  75. xxxx:0220  C0 74 22 B4 0E BB 07 00-CD 10 EB F2 33 D2 F7 36   .t".........3..6   
  76. xxxx:0230  18 7C FE C2 88 16 30 7C-33 D2 F7 36 1A 7C 88 16   .|....0|3..6.|..   
  77. xxxx:0240  1F 7C A3 2E 7C C3 B4 02-8B 16 2E 7C B1 06 D2 E6   .|..|......|....   
  78. xxxx:0250  0A 36 30 7C 8B CA 86 E9-8B 16 1E 7C CD 13 C3 0D   .60|.......|....   
  79. xxxx:0260  0A 4E 6F 6E 2D 53 79 73-74 65 6D 20 64 69 73 6B   .Non-System disk   
  80. xxxx:0270  20 6F 72 20 64 69 73 6B-20 65 72 72 6F 72 0D 0A    or disk error..   
  81. xxxx:0280  52 65 70 6C 61 63 65 20-61 6E 64 20 73 74 72 69   Replace and stri   
  82. xxxx:0290  6B 65 20 61 6E 79 20 6B-65 79 20 77 68 65 6E 20   ke any key when    
  83. xxxx:02A0  72 65 61 64 79 0D 0A 00-0D 0A 44 69 73 6B 20 42   ready.....Disk B   
  84. xxxx:02B0  6F 6F 74 20 66 61 69 6C-75 72 65 0D 0A 00 49 42   oot failure...IB   
  85. xxxx:02C0  4D 42 49 4F 20 20 43 4F-4D 49 42 4D 44 4F 53 20   MBIO  COMIBMDOS    
  86. xxxx:02D0  20 43 4F 4D 00 00 00 00-00 00 00 00 00 00 00 00    COM............   
  87. xxxx:02E0  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................   
  88. xxxx:02F0  00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA   ..............U.   
  89.  
  90. I've listed the boot sector only so that you can compare it to 
  91. your's and see if it's intact.  In my case it wasn't and I had to 
  92. get it from another disk.  Alternatively you could enter it onto 
  93. the disk using debug.
  94.  
  95. The next portion of your disk is the FAT.  Here is what the first 
  96. portion of mine looks like.
  97.  
  98. xxxx:0300  F8 FF FF FF 03 00 04 00-05 00 06 00 FF FF 08 00   ................   
  99. xxxx:0310  09 00 0A 00 0B 00 0C 00-0D 00 0E 00 0F 00 10 00   ................   
  100. xxxx:0320  11 00 12 00 13 00 14 00-FF FF 16 00 17 00 18 00   ................   
  101. xxxx:0330  19 00 1A 00 1B 00 1C 00-1D 00 1E 00 1F 00 20 00   .............. .   
  102. xxxx:0340  FF FF FF FF FF FF FF FF-25 00 26 00 27 00 28 00   ........%.&.'.(.   
  103. xxxx:0350  29 00 2A 00 2B 00 2C 00-FF FF 2E 00 2F 00 30 00   ).*.+.,...../.0.   
  104. xxxx:0360  31 00 32 00 33 00 34 00-35 00 36 00 37 00 38 00   1.2.3.4.5.6.7.8.   
  105. xxxx:0370  39 00 3A 00 3B 00 3C 00-3D 00 3E 00 3F 00 40 00   9.:.;.<.=.>.?.@.   
  106.  
  107. The FAT is the road map which DOS uses to find it's way around 
  108. your disk.  When DOS needs to access a file it finds the first 
  109. sector the file is in by looking it up in the directory listing.
  110. Then it takes a look at the FAT listing for that sector.  If the 
  111. FAT for that sector is a FFFF there are no more sectors for DOS 
  112. to read.  If there is a number there that is the number to the 
  113. next sector which the file is in.  DOS goes to the next sector 
  114. and continues on until it reaches a FFFF.
  115.  
  116. It's fairly easy to read this.  Each word (2 bytes) corresponds
  117. to a disk sector.  Two rules to this table.  All the numbers are 
  118. in hex and the words have the bytes reversed.  So if you were 
  119. looking at a word from the table that read "EF 12" first you 
  120. would invert them "12 EF".  Next convert them to decimal. 
  121. 12EF hex = 4847 decimal.
  122.  
  123. The first file starts in sector 2, goes to 3, 4, 5 and then
  124. 6 where it reads a FFFF and stops.  Since your system files are 
  125. normally the first files on a disk the first couple of files
  126. should be contiguous.  This will help you locate the start of
  127. your FAT.  
  128.  
  129. Hopefully the next figure will make it clearer.
  130.  
  131. Sector -->   0     1     2     3     4     5     6     7
  132.              |     |     |     |     |     |     |     |
  133.             / \   / \   / \   / \   / \   / \   / \   / \
  134. xxxx:0300  F8 FF FF FF 03 00 04 00-05 00 06 00 FF FF 08 00   ................   
  135.  
  136.  
  137. Sector -->   8     9     10    11    12    13    14    15
  138.              |     |     |     |     |     |     |     |
  139.             / \   / \   / \   / \   / \   / \   / \   / \
  140. xxxx:0310  09 00 0A 00 0B 00 0C 00-0D 00 0E 00 0F 00 10 00   ................   
  141.  
  142.  
  143. Sector -->   16    17    18    19    20    21    22    23
  144.              |     |     |     |     |     |     |     |
  145.             / \   / \   / \   / \   / \   / \   / \   / \
  146. xxxx:0320  11 00 12 00 13 00 14 00-FF FF 16 00 17 00 18 00   ................   
  147.  
  148. The first byte is is not a sector but a special marker which 
  149. tells DOS what type of disk it is.
  150.  
  151.  
  152. Now that you have an idea how to read the FAT I'll explain a 
  153. little bit about DEBUG so that you can read the FAT from your 
  154. disk and manipulate it if neccessary.
  155.  
  156. First DEBUG only understands hexadecimal numbers.  So in the 
  157. following discussion all numbers are in hex unless otherwise 
  158. noted.
  159.  
  160. DEBUG uses single letters for all it's commands.  The ones you 
  161. will need are explained below.  There are more DEBUG commands but 
  162. since explaining DEBUG is not the intent of this file I will have 
  163. to direct you to your manual for any additional ones you may be 
  164. interested in.  The DEBUG prompt is a very unimposing dash "-".
  165. All commands are entered from the "-".
  166.  
  167. Dump command - displays a portion of memory
  168.  
  169.       syntax - D address or range
  170.                address - address to start displaying memory
  171.                range - range of memory to display
  172.        notes - if no address is specified display starts at 
  173.                current instruction pointer address
  174.  
  175.  
  176. Fill command - fills a specified range of memory with any list 
  177.                of characters
  178.  
  179.       syntax - F range list
  180.                range - fill specified range
  181.                list - bytes to fill range with
  182.  
  183.  
  184. Load command - Loads a file or disk sectors into memory
  185.  
  186.       syntax - L address drive sector sector
  187.                address - memory address to start loading at
  188.                drive - drive number to load from (A: is 0, B: is 1)
  189.                sector - beginning sector of drive
  190.                sector - ending sector of drive
  191.        notes - max sectors to load is 80 (hex)
  192.  
  193.  
  194. Move command - Moves the contents of memory from one location to 
  195.                another.
  196.  
  197.       syntax - M range address
  198.                range - range of memory to move
  199.                address - address to move to
  200.        notes - actually this is a copy operation.  The source 
  201.                code isn't changed unless the move operation
  202.                overwrites it.
  203.  
  204.  
  205. Name command - assigns a name for the W command to use
  206.  
  207.       syntax - N d:path filename.ext
  208.        notes - drive and path are optional.
  209.  
  210.  
  211. Quit command - quit debug
  212.  
  213.       syntax - Q
  214.        notes - self explanatory
  215.  
  216.  
  217. Register command - displays and optionally changes value of a 
  218.                    register 
  219.  
  220.           syntax - R registername
  221.                    registername - name of register to change.
  222.  
  223.  
  224. Search command - Searches a specified area of memory
  225.  
  226.         syntax - S range list
  227.                  range - range of memory to search
  228.                  list - list of bytes to search for
  229.          notes - if no matches are found you will be returned to 
  230.                  the DEBUG prompt        
  231.  
  232.  
  233. Write command - writes the contents of memory to disk
  234.  
  235.        syntax - W address drive sector sector
  236.                 address - beginning address of memory to write
  237.                 drive - drive to write to
  238.                 sector - sector to begin writing on
  239.                 sector - number of sectors to write
  240.         notes - this is a VERY DANGEROUS command as you are 
  241.                 writing to absolute disk sectors and bypassing DOS.  
  242.                 Ensure you are entering correct information.  There
  243.                 is no backing up from this one.
  244.               - if writing to a file the CX register must be set.
  245.  
  246.  
  247. Now to the actual steps to fix your FAT (we hope).  Boot your 
  248. computer with a system formatted disk in A:  Have the minimum of 
  249. files on this disk as we will be writing the FAT to this disk in 
  250. case of a mistake.  The only files you should need beside the 
  251. system files is COMMAND.COM and DEBUG.COM  In the following
  252. discussion it is assumed your hard disk is C:
  253.  
  254. First you have to load the entire FAT into memory.  If your disk 
  255. is setup different then mine you will have to experiment to load 
  256. just the boot sector and FAT.  Before we load the FAT, just to 
  257. make sure we'll clear the spot of memory we're going to use.
  258. Remember that all numbers are in hex.  Do not type the items in 
  259. {notes and explanations}
  260.  
  261. To find the second copy of the FAT you can search for the first 
  262. four bytes of the FAT or the sequence of sectors 3, 4, 5.  Then 
  263. subtract the start of the first FAT from the start of the second. 
  264. This will give you the length of the FAT.  Then add the length 
  265. of the FAT to the start of the second FAT.  This should be the 
  266. end of the second FAT.  Make sure this is the end of the display 
  267. in memory.
  268.  
  269. The xxxx can be any number, it depends on your computer.
  270.  
  271. A:\                       {DOS prompt}                                      
  272.  
  273. >debug                    {enter DEBUG}                                      
  274.  
  275. -F 0 ffff 00              {fill memeory with 0's just in case}                                      
  276.  
  277. -L 100 3 0 53             {load boot sector and FAT}                                                      
  278.                                                                                 
  279. -S 0 L FFFF F8 FF FF FF   {search from 0 to FFFF for the 
  280.                            string F8 FF FF FF}
  281.                                                               \
  282. xxxx:0300                 {my computer responds with this      \
  283. xxxx:5500                  first FAT at 0300, second at 5500}   \ 
  284.                                                                  \
  285.                                                                  OR
  286.                                                                  /
  287.                                                                 /
  288.                                                                /
  289. -S 0 FFFF 03 00 04 00     {search from 0 to FFFF for the      /
  290.                            string 03 00 04 00}
  291.  
  292. xxxx:0304                 {FAT starts at even number 0300
  293. xxxx:5504                  and 5500} 
  294.  
  295. -D 5500                   {display second FAT to make sure we can use it}                                                      
  296.  
  297. xxxx:5500  F8 FF FF FF 03 00 04 00-05 00 06 00 FF FF 08 00   ................   
  298. xxxx:5510  09 00 0A 00 0B 00 0C 00-0D 00 0E 00 0F 00 10 00   ................   
  299. xxxx:5520  11 00 12 00 13 00 14 00-FF FF 16 00 17 00 18 00   ................   
  300. xxxx:5530  19 00 1A 00 1B 00 1C 00-1D 00 1E 00 1F 00 20 00   .............. .   
  301. xxxx:5540  FF FF FF FF FF FF FF FF-25 00 26 00 27 00 28 00   ........%.&.'.(.   
  302.  
  303.  
  304. A-rcx                      {change CX register to end of FAT}                                                      
  305.  
  306. CX 0000                   {DEBUG responds with this}                                                      
  307.  
  308. :a600                     {you type this, may need to be adjusted 
  309.                            for your disk}                                                      
  310.  
  311. -n fatc                   {write file to floppy disk with this name,
  312.                            this is the backup in case a mistake is made}
  313.  
  314. -w                        {this will write your C: FAT to floppy}
  315.  
  316. Writing A600 bytes        {DEBUG responds with this}
  317.  
  318. -q                        {quit DEBUG}
  319.  
  320. At this point you should check the file on the floppy.  It should 
  321. be about 50K long.  Look at it using your favorite viewing 
  322. program to make sure it was written correctly.  The biggest item 
  323. to look for is that the boot sector is the first portion of the 
  324. file.
  325.  
  326.  
  327. Up to this point we haven't modified anything on the hard drive.  
  328. The next step will directly modify the sectors on the hard drive. 
  329. Make sure you understand what you are doing if your disk is 
  330. configured different than mine.
  331.  
  332.  
  333. :\                       {DOS prompt}                                      
  334.  
  335. >debug                    {enter DEBUG}                                      
  336.  
  337. -f 0 ffff 00              {fill memeory with 0's just in case}                                      
  338.  
  339. -l 100 3 0 53             {load boot sector and FAT}                                                      
  340.  
  341. -M 5500 A700 300          {copy second FAT to position of first FAT}
  342.  
  343. -W 100 3 0 53             {write the whole thing back to hard disk.
  344.                            this is the inverse of the L command}
  345. -Q                        {quit debug}
  346.  
  347. If everything worked your hard drive should now be operational.  
  348. I recommend you run chkdsk to see if there are any errors, fix 
  349. them if any, backup your disk, then do a low level format.  
  350.  
  351. If you find this file useful (or suggestions to expand it) you 
  352. can reach me at EXEC-PC 414-768-5160
  353.                 MBBS    414-xxx-xxxx
  354.                 
  355. Erik Dufek
  356.